<script lang="ts" setup>
import http from '../http'
import Icon from '@/components/Icon/src/Icon.vue'
import { ref } from 'vue'
import { useCopyToClipboard } from '@/hooks/web/useCopyToClipboard'
import { Toast } from 'vant'
import { useI18n } from 'vue-i18n'
import { state } from '../dapp'
import BgVue from '@/components/BgVue.vue'

const { t } = useI18n()
const { copyText } = useCopyToClipboard()

const walletAddress = ref(state.address)
// const personalAddress = ref('0Xsbcbsdjb324235234534')
const officialWebsite = ref('https://playtimedao.io')

const inviteAddress = ref('')
const count = ref(0)

type ItemType = {
  address: string
  time: string
}
// const list = ref<ItemType[]>([])
async function init() {
  const res = await http.get('/api/user/friends')
  if (res.code === 200) {
    inviteAddress.value = res.data.inviteAddress
    count.value = res.data.count
    // list.value = res.data.list.map((row: any) => {
    //   return {
    //     address: row.address.substr(0, 20) + '...' + row.address.substr(38),
    //     time: row.create_time.substr(0, 16).replace('T', ''),
    //   }
    // })
  }
}

const communityData = ref({
  beforeYesterday: '0',
  size: 0,
  threeDaysAgo: '0',
  yesterday: '0',
})
async function initCommunity() {
  const res = await http.get('/api/user/community')
  if (res.code === 200) {
    communityData.value = res.data
  }
}

init()
initCommunity()

// if (!import.meta.env.PROD) {
//   inviteAddress.value =
//     '0Xsbcbsdjb3242352345340Xsbcbsdjb3242352345340Xsbcbsdjb3242352345340Xsbcbsdjb3242352345340Xsbcbsdjb3242352345340Xsbcbsdjb3242352345340Xsbcbsdjb324235234534'

//   list.value.push({
//     address:
//       '0Xsbcbsdjb3242352345340Xsbcbsdjb3242352345340Xsbcbsdjb3242352345340Xsbcbsdjb324235234534',
//     time: '20202-02-02 00:00',
//   })
// }

function copyWallet() {
  copyText(walletAddress.value, () => {
    Toast.success(t('common.copySuccess'))
  })
}
// function copyPersonal() {
//   copyText(personalAddress.value, () => {
//     Toast.success(t('common.copySuccess'))
//   })
// }
function copyWebsite() {
  copyText(officialWebsite.value, () => {
    Toast.success(t('common.copySuccess'))
  })
}
</script>

<template>
  <div class="myFriend2-wrap">
    <BgVue>
      <template #imgFixed>
        <img src="@/assets/imgV2/exchange-bg-bottom.jpg" />
      </template>
      <template #img>
        <img src="@/assets/imgV2/myFriend-bg.png" />
      </template>
      <div class="myFriend2">
        <div class="top-box">
          <div class="tit"> {{ t('Myfriend.QBDZ') }} </div>
          <div class="text" @click="copyWallet">
            <span class="align-middle">{{ walletAddress }}</span>

            <Icon class="cp align-middle" icon="ri:file-copy-2-fill"></Icon>
          </div>
        </div>
        <!-- <div class="box">
      <div class="tit"> 个人地址 </div>
      <div class="text" @click="copyPersonal">
        <span class="align-middle">{{ personalAddress }}</span>

        <Icon class="cp align-middle" icon="ri:file-copy-2-fill"></Icon>
      </div>
    </div> -->
        <div class="box">
          <div class="tit"> {{ t('Myfriend.website') }}: </div>
          <div class="text" @click="copyWebsite">
            <span class="align-middle">{{ officialWebsite }}</span>

            <Icon class="cp align-middle" icon="ri:file-copy-2-fill"></Icon>
          </div>
        </div>
        <div class="bottom-box">
          <div class="list">
            <div class="item">
              <div class="lb">{{ t('Myfriend.recommenders') }}：</div>
              <div class="v">
                <div class="v-w">{{ inviteAddress }}</div>
              </div>
            </div>
            <div class="item">
              <div class="lb"
                ><span>{{ t('Myfriend.friend') }}：</span>
                <span>{{ count }}</span>
              </div>
              <div class="v">
                <router-link to="/friends">{{
                  t('Myfriend.check')
                }}</router-link>
              </div>
            </div>
            <div class="item">
              <div class="lb"
                ><span>{{ t('Myfriend.myCommunity') }}：</span
                ><span>{{ communityData.size }}</span></div
              >
              <div class="v">
                <div class="row">
                  <div class="row_l">{{ t('Myfriend.yesterday') }} </div>
                  <div class="row_r">{{ communityData.yesterday }}</div>
                </div>
                <div class="row">
                  <div class="row_l">{{ t('Myfriend.beforeYesterday') }} </div>
                  <div class="row_r">{{ communityData.beforeYesterday }}</div>
                </div>
                <div class="row">
                  <div class="row_l">{{ t('Myfriend.threeDaysAgo') }} </div>
                  <div class="row_r">{{ communityData.threeDaysAgo }}</div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- <div class="friend-box">
        <div class="tit"> {{ t('Myfriend.friend') }} </div>
        <div class="list">
          <div v-for="(item, index) in list" :key="index" class="item">
            <div class="l">
              <div class="no">{{ index + 1 }}</div>
            </div>
            <div class="m">
              <div class="label">{{ t('Myfriend.address') }}</div>
              <div class="val">{{ item.address }}</div>
            </div>
            <div class="r">
              <div class="label">{{ t('Myfriend.time') }}</div>
              <div class="val">{{ item.time }}</div>
            </div>
          </div>
        </div>
      </div> -->
      </div>
    </BgVue>
  </div>
</template>

<style lang="less" scoped>
.myFriend2-wrap {
  padding-bottom: (267px/2);
  background: url(@/assets/imgV2/BlockchainGame-bg.png) no-repeat 0 bottom;
  background-size: 100% auto;
  min-height: calc(100vh - 62px);
  // & > :deep(.BgFixed) {
  //   background-image: linear-gradient(0deg, #177dcf 0%, #68bafe 100%);
  //   min-height: 680px;
  //   img {
  //     position: absolute;
  //     bottom: 0;
  //     height: auto;
  //   }
  // }
}
.myFriend2 {
  // padding: 0 20px 40px;
  // color: #ebb90c;
  font-size: 15px;
  text-align: left;
  // font-weight: bold;
  .cp {
    margin-left: 6px;
    color: #fff;
  }

  .align-middle {
    vertical-align: middle;
  }

  .top-box {
    padding: 40px 36px 0 110px;
    // height: 108px;
    // background-color: #ebb90c;
    // border-radius: 15px;

    .tit {
      padding: 20px 0 6px;
      color: #ffd166;
      font-size: 16px;
      text-shadow: #00000033 1px 0 3px, #00000033 0 1px 3px,
        #00000033 -1px 0 3px, #00000033 0 -1px 3px;

      letter-spacing: 1px;
    }

    .text {
      height: 69px;
      word-wrap: break-word;
      color: #fff;
    }
  }

  .box {
    padding: 20px 46px;
    color: #0e509a;
    white-space: nowrap;

    .tit {
      // padding: 8px 0;
      display: inline;
      vertical-align: middle;
    }

    .text {
      // padding: 8px 0;
      display: inline;
      vertical-align: middle;
    }
  }

  // .top-box + .box {
  //   margin-top: 20px;
  //   border-bottom: 1px solid #ebb90c;
  // }

  .bottom-box {
    // margin-top: 12px;

    .list {
      padding: 15px 10px;
      margin: 28px;
      background-color: #52a4ef;
      box-shadow: 0px 1px 18px 0px rgba(5, 18, 100, 0.5);
      border-radius: 25px 25px 20px 20px;
    }

    .item {
      // display: flex;
      // padding: 36px 50px 0;
      // padding-right: 20px;

      background-color: #98d8f8;
      box-shadow: 0px 4px 10px 0px rgba(191, 63, 38, 0.4);
      border-radius: 18px;
      border: solid 3px #ffffff;
      padding: 18px 20px;
    }
    .item + .item {
      margin-top: 15px;
    }

    // .item:first-child {
    //   // height: 130px;
    //   // padding: 36px 58px 0;
    //   // border-bottom: 1px solid #ebb90c;
    //   .lb {
    //     padding: 20px 0 12px;
    //   }
    //   .v {
    //     // height: 30px;
    //     text-align: left;
    //   }
    // }

    .lb {
      display: flex;
      justify-content: space-between;
      color: #d78908;
      // flex: 1;
      font-size: 15px;
      line-height: 1;

      // -webkit-text-stroke: 1px #ee4e39;
      // font-weight: normal;
      // text-align: center;

      // text-shadow: #0e509a 2px 0 2px, #0e509a 0 2px 2px, #0e509a -2px 0 2px,#0e509a 0 -2px 2px;
    }

    .v {
      // flex: 1;
      // display: flex;
      // justify-content: flex-end;
      // align-items: center;
      color: #0e509a;
      // text-align: center;
      padding-top: 12px;
      a {
        color: inherit;
        text-decoration: underline;
      }
    }

    .v-w {
      word-break: break-all;
      width: 100%;
    }

    .row {
      display: flex;
      justify-content: space-between;
    }
    .row + .row {
      padding-top: 2px;
    }

    // .text-right {
    //   text-align: right;
    // }
  }

  // .friend-box {
  //   font-size: 12px;

  //   .tit {
  //     padding: 10px 10px;
  //   }

  //   .item {
  //     display: flex;
  //     background-color: hsla(47, 90%, 48%, 0.08);
  //     border-radius: 10px;
  //     padding: 10px 0;
  //   }

  //   .item + .item {
  //     margin-top: 10px;
  //   }

  //   .l {
  //     display: flex;
  //     align-items: center;
  //     padding-left: 16px;
  //   }

  //   .m {
  //     flex: 1;
  //     padding: 0 10px;
  //   }

  //   .r {
  //     padding-right: 18px;
  //     text-align: right;
  //   }

  //   .no {
  //     width: 25px;
  //     height: 25px;
  //     color: #ebb90c;
  //     text-align: center;
  //     line-height: 25px;
  //     background-color: #5c4e1c;
  //     border-radius: 25px;
  //   }

  //   .label {
  //   }

  //   .val {
  //     margin-top: 7px;
  //     word-break: break-all;
  //   }
  // }
}
</style>
